package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Purchase;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController

@RequestMapping("purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;


    @GetMapping("{id}")
    public Result findById(@PathVariable long id) {
        return purchaseService.findById(id);
    }

    @GetMapping("{type}/{page}/{size}")
    public Result findByType(@PathVariable String type,@PathVariable int page,@PathVariable int size){
        return purchaseService.findPurchaseByType(type,page,size);
    }

    @GetMapping
    public Result findAll() {
        return purchaseService.findAll();
    }


    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id) {
        System.out.println(id);
        return purchaseService.deleteById(id);
    }

    @PostMapping
    public Result save(@RequestBody Purchase purchase) { return purchaseService.save(purchase); }

    @PutMapping
    public Result update(@RequestBody Purchase purchase) { return purchaseService.update(purchase); }

    @PutMapping("status/{id}")
    public Result updateStatus(@PathVariable Long id){
        return purchaseService.updatestatus(id);
    }
}
